package com.learn.xueer.ui.activity

import android.os.Bundle
import androidx.fragment.app.Fragment
import com.learn.xueer.app.base.BaseActivity1
import com.learn.xueer.app.ext.bindViewPager2
import com.learn.xueer.app.ext.init
import com.learn.xueer.data.model.bean.GradeResponse
import com.learn.xueer.databinding.ActivityHearBinding
import com.learn.xueer.ui.fragment.HearFragment
import kotlinx.android.synthetic.main.include_viewpager.magic_indicator
import kotlinx.android.synthetic.main.include_viewpager.view_pager
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel

class HearActivity : BaseActivity1<BaseViewModel, ActivityHearBinding>() {

    //标题集合
    var mDataList: ArrayList<GradeResponse> = arrayListOf()

    //fragment集合
    var fragments: ArrayList<Fragment> = arrayListOf()
    override fun initView(savedInstanceState: Bundle?) {
        mViewBind.click = ProxyClick()
        mDataList.add(GradeResponse(null, "全部"))
        mDataList.add(GradeResponse(1107, "七年级"))
        mDataList.add(GradeResponse(1108, "八年级"))
        mDataList.add(GradeResponse(1109, "九年级"))
        mDataList.add(GradeResponse(1206, "其他"))

        mDataList.forEach {
            fragments.add(HearFragment.newInstance(it.id ?: -1))
        }


        //初始化viewpager2
        view_pager.init(this, fragments, false)
        view_pager.offscreenPageLimit = fragments.size
        //初始化 magic_indicator
        magic_indicator.bindViewPager2(view_pager, mDataList)

    }

    inner class ProxyClick {
        fun returnBack() {
            finish()
        }

        fun search() {}
    }
}